{% extends "index.html" %}
{% block title %}
    添加电梯
{% endblock %}
{% block page_nav %}
	<li>电梯</li>
    <li>添加电梯</li>
{% endblock %}
{#页面内容#}
{% block content %}
    <!--数据录入-->
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-title">
                    <div style="margin-bottom: 30px; border-bottom: #2b333e; border-bottom-style: solid; padding-bottom: 15px">
                        <h3>电梯基础信息录入</h3>
                    </div>
                    {% if messages %}
                        <div class="alert alert-warning">
                            {% for message in messages %}
                                {% for key in messages[message] %}
                                    <p>{{ key }}</p>
                                {% endfor %}
                            {% endfor %}
                        </div>
                    {% endif %}
                </div>
                <div class="card-body">
                    <form class="form-horizontal" method="post" action="{{ url_for('view.elevator_basic_data_input') }}" id="form">
                        <div class="form-group">
                            <label class="control-label col-md-1" for="maintenanceContractNumber">合同编号</label>
                            <div class="col-md-3">
                                <input id="maintenanceContractNumber" class="form-control" type="text" name="maintenanceContractNumber" placeholder="合同编号" readonly>
                            </div>
                            <label class="control-label col-md-1" for="idCode">识别码</label>
                            <div class="col-md-3">
                                <input id="idCode" class="form-control" type="text" name="idCode" placeholder="识别码" readonly>
                            </div>
                            <label class="control-label col-md-1" for="deviceName">设备名称</label>
                            <div class="col-md-3">
                                <input id="deviceName" class="form-control" type="text" name="deviceName" placeholder="设备名称" readonly>
                            </div>
                        </div>
                        <!--分隔符-->
                        <div class="card-diver">
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="userEntityName">使用单位</label>
                            <div class="col-md-7">
                                <input id="userEntityName" type="text" class="form-control" list="list_userunit" name="userEntityName" placeholder="使用单位">
                                    <datalist id="list_userunit">
                                        {% for userunit in userunits %}
                                            <option>{{ userunit.userEntityName }}</option>
                                        {% endfor %}
                                    </datalist>
                            </div>
                            <label class="control-label col-md-1" for="userEntityCode">使用单位代码</label>
                            <div class="col-md-3">
                                <input id="userEntityCode" class="form-control" type="text" name="userEntityCode" placeholder="使用单位代码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="locationOfUse">使用地点</label>
                            <div class="col-md-7">
                                <input id="locationOfUse" class="form-control" type="text" name="locationOfUse" placeholder="使用地点" required>
                            </div>
                            <label class="control-label col-md-1" for="numberOfUse">使用编号</label>
                            <div class="col-md-3">
                                <input id="numberOfUse" class="form-control" type="text" name="numberOfUse" placeholder="使用编号" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="model">型号</label>
                            <div class="col-md-3">
                                <input id="model" class="form-control" type="text" name="model" placeholder="型号">
                            </div>
                            <label class="control-label col-md-1" for="regCode">注册代码</label>
                            <div class="col-md-3">
                                <input id="regCode" class="form-control" type="text" name="regCode" placeholder="注册代码" required pattern="[0-9]{18}" title="18位数字" maxlength="18">
                            </div>
                            <label class="control-label col-md-1" for="factoryNumber">出厂编号</label>
                            <div class="col-md-3">
                                <input id="factoryNumber" class="form-control" type="text" name="factoryNumber" placeholder="出厂编号" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="manufactureCompany">制造单位</label>
                            <div class="col-md-7">
                                <input id="manufactureCompany" class="form-control" type="text" name="manufactureCompany" placeholder="制造单位" required>
                            </div>
                            <label class="control-label col-md-1" for="manufactureDate">制造日期</label>
                            <div class="col-md-3">
                                <input class="form-control datepicker" id="manufactureDate" type="text" name="manufactureDate" placeholder="制造日期" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="installCompany">安装单位</label>
                            <div class="col-md-7">
                                <input id="installCompany" class="form-control" type="text" name="installCompany" placeholder="安装单位" required>
                            </div>
                            <label class="control-label col-md-1" for="installDate">安装日期</label>
                            <div class="col-md-3">
                                <input class="form-control datepicker" id="installDate" type="text" name="installDate" placeholder="安装日期" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="renovateCompany">改造单位</label>
                            <div class="col-md-7">
                                <input id="renovateCompany" class="form-control" type="text" name="renovateCompany" placeholder="改造单位" value="/">
                            </div>
                            <label class="control-label col-md-1" for="renovateDate">改造日期</label>
                            <div class="col-md-3">
                                <input class="form-control datepicker" id="renovateDate" type="text" name="renovateDate" placeholder="改造日期" value="/">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="majorRepairCompany">重大修理单位</label>
                            <div class="col-md-7">
                                <input id="majorRepairCompany" class="form-control" type="text" name="majorRepairCompany" placeholder="重大修理单位" value="/">
                            </div>
                            <label class="control-label col-md-1" for="majorRepairDate">重大修理日期</label>
                            <div class="col-md-3">
                                <input class="form-control datepicker" id="majorRepairDate" type="text" name="majorRepairDate" placeholder="重大修理日期" value="/">
                            </div>
                        </div>
                        <!--分隔符-->
                        <div class="card-diver">
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="contactPerson">联系人</label>
                            <div class="col-md-3">
                                <input id="contactPerson" class="form-control" type="text" name="contactPerson" placeholder="联系人" required>
                            </div>
                            <label class="control-label col-md-1" for="contactNumber">联系号码</label>
                            <div class="col-md-3">
{#                                pattern="^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$" title="11位手机号码" 限制为手机号码格式，目前不限制#}
                                <input id="contactNumber" class="form-control" type="text" name="contactNumber" placeholder="联系号码" required onkeyup="value=value.replace(/[^\d]/g,'')">
                            </div>
                            <label class="control-label col-md-1" for="liA">电梯司机</label>
                            <div class="col-md-3">
                                <input id="liA" class="form-control" type="text" name="liA" placeholder="电梯司机" required value="/">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="saM">安全管理员</label>
                            <div class="col-md-3">
                                <input id="saM" class="form-control" type="text" name="saM" placeholder="安全管理员" required>
                            </div>
                            <label class="control-label col-md-1" for="safetyManagerCertificate">安全管理员证号</label>
                            <div class="col-md-3">
                                <input id="safetyManagerCertificate" class="form-control" type="text" name="safetyManagerCertificate" placeholder="安全管理员证号">
                            </div>
                            <label class="control-label col-md-1" for="liftAttendantCertificate">电梯司机证号</label>
                            <div class="col-md-3">
                                <input id="liftAttendantCertificate" class="form-control" type="text" name="liftAttendantCertificate" placeholder="电梯司机证号" value="/">
                            </div>
                        </div>
                        <!--分隔符-->
                        <div class="card-diver">
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="maintenanceLevel">维保等级</label>
                            <div class="col-md-3">
                                <select id="maintenanceLevel" name="maintenanceLevel" class="form-control">
                                    <option value="A" selected="selected">维保等级A</option>
                                    <option value="B">维保等级B</option>
                                    <option value="C">维保等级C</option>
                                </select>
                            </div>
                            <label class="control-label col-md-1" for="maintenancePersonA">维保人员A</label>
                            <div class="col-md-3">
                                <input id="maintenancePersonA" type="text" class="form-control" list="itemlistA" name="maintenancePersonA" placeholder="维保人员A">
                                    <datalist id="itemlistA">
                                        {% for maintenancePerson in maintenancepeople %}
                                            <option>{{ maintenancePerson.name }}</option>
                                        {% endfor %}
                                    </datalist>
                            </div>
                            <label class="control-label col-md-1" for="maintenancePersonB">维保人员B</label>
                            <div class="col-md-3">
                                <input id="maintenancePersonB" type="text" class="form-control" list="itemlistB" name="maintenancePersonB" placeholder="维保人员B">
                                    <datalist id="itemlistB">
                                        {% for maintenancePerson in maintenancepeople %}
                                            <option>{{ maintenancePerson.name }}</option>
                                        {% endfor %}
                                    </datalist>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="mSDate">合同开始日期</label>
                            <div class="col-md-3">
                                <input id="mSDate" class="form-control datepicker" type="text" name="mSDate" placeholder="合同开始日期" required>
                            </div>
                            <label class="control-label col-md-1" for="mEDate">合同结束日期</label>
                            <div class="col-md-3">
                                <input id="mEDate" class="form-control datepicker" type="text" name="mEDate" placeholder="合同结束日期" required>
                            </div>
                            <label class="control-label col-md-1" for="perinspectionDate">定期检验日期</label>
                            <div class="col-md-3">
                                <input id="perinspectionDate" class="form-control datepicker" type="text" name="perinspectionDate" placeholder="定期检验日期" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-1" for="maintenanceRemark">维保备注</label>
                            <div class="col-md-11">
                                <textarea class="form-control" id="maintenanceRemark" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="card-footer">
                            <div class="row">
                                <div class="col-md-2 col-md-offset-4" >
                                    <button id="next" class="btn btn-primary icon-btn" type="button"><i class="fa fa-fw fa-lg fa-check-circle"></i>下一步</button>
                                </div>
                                <div class="col-md-2 col-md-offset-1">
                                    <button id="reset" class="btn btn-primary icon-btn" type="reset"><i class="fa fa-fw fa-lg fa-refresh"></i>重置</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block script %}
    {{ super() }}
    {# 日期选择器插件bootstrap-datepicker #}
    <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap-datepicker/bootstrap-datepicker.min.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap-datepicker/bootstrap-datepicker.zh-CN.min.js') }}"></script>
    {# 电梯初始数据加载 #}
    <script type="text/javascript" src="{{ url_for('static', filename='js/elevator_data.js') }}"></script>
    {# 提示插件 #}
    <script type="text/javascript" src="{{ url_for('static', filename='js/alert.js') }}"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var key;
            {% if elevator_cp_data != '' %}
                <!--电梯录入数据初始值赋值-->
                {#for (key in dics){#}
                {#    $('#'+key).val(dics[key]);#}
                {% for key in elevator_cp_data %}
                    $('#{{ key }}').val("{{ elevator_cp_data[key] }}");
                {% endfor %}
            {% endif %}
            {% for key in keys %}
                $('#{{ key }}').val("{{ form_init[key] }}");
            {% endfor %}
        });

        $('.datepicker').datepicker();

        <!--输入数据逻辑判断，出错则输出错误信息-->
        function warning(){
            var failtext = [];

            {#安装日期与制造日期比较#}
            if ($('#installDate').val() < $('#manufactureDate').val()) {
                failtext.push('录入的安装日期错误，不可早于制造日期');
            }

            {#维保开始时间与结束时间比较#}
            if ($('#mEDate').val() < $('#mSDate').val()) {
                failtext.push('录入的维保结束日期错误，不可早于维保开始日期');
            }

            {#维保开始时间与结束时间比较#}
            if ($('#maintenancePersonA').val() == $('#maintenancePersonB').val()) {
                failtext.push('维保人员为同一个人');
            }
            return failtext;
        }

        $('#next').click(function () {
            var message = warning();
            if (message.length > 0){
                ShowTipAlwaysInTheMiddle(message[0], 'danger');
            }
            else {
                $('#form').submit();
            }

        });

        $('#btn_reset').click(function () {
            location.reload();
        });
    </script>
{% endblock %}